import axios from "axios"
const baseURL = "http://127.0.0.1:8888/api/private/v1/"
axios.defaults.baseURL = baseURL

// 登录拦截
axios.interceptors.request.use(function (config) {
    // console.log(11, config)
    let token = localStorage.getItem('myToken')
    if (token) {
        config.headers.Authorization = token
    }
    return config;
}, function (error) {
    return Promise.reject(error);
});
// 登录请求
export const checkLogin = params => axios.post('login', params).then(res => res.data)
// 获取用户列表
export const getUsers = params => axios.get('users', params).then(res => res.data)
// 修改用户状态
export const setUserStatus = params => axios.put(`users/${params.uid}/state/${params.type}`).then(res => res.data)
// 添加用户
export const addUsers = params => axios.post('users', params).then(res => res.data)
// 获取用户信息
// export const editUsersId = params => axios.get(`users/${params}`).then(res => res.data)
// 编辑用户信息
export const editUsersId = params => axios.put(`users/${params.id}`, params).then(res => res.data)
// 删除用户信息
export const deleteUser = params => axios.delete(`users/${params}`).then(res => res.data)
// 获取角色列表
export const getRoleList = () => axios.get('roles').then(res => res.data)
// 分配角色
export const grantUserRole = params => axios.put(`users/${params.id}/role`, { id: params.id, rid: params.rid }).then(res => res.data)





